#是库的构建文件
# 检查必要工具
ifeq (, $(shell which g++))
$(error "g++ not found, please install build-essential")
endif

# 检查C++17支持
CXX_VERSION := $(shell g++ -dumpversion)
ifeq ($(shell expr $(CXX_VERSION) \< 7), 1)
$(error "g++ version $(CXX_VERSION) is too old, need at least 7.0 for C++17 support")
endif

# 主配置
CXX = g++
CXXFLAGS = -fPIC -Wall -Wextra -Wpedantic -std=c++17
LDFLAGS = -shared
LDLIBS = -ludev -lblkid
TARGET = libStorageManager.so
SOURCES = StorageManager.cpp
OBJECTS = $(SOURCES:.cpp=.o)

# 调试选项
DEBUG ?= 0
ifeq ($(DEBUG), 1)
    CXXFLAGS += -g -O0
else
    CXXFLAGS += -O2
endif

all: $(TARGET)

$(TARGET): $(OBJECTS)
	$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)

%.o: %.cpp
	$(CXX) $(CXXFLAGS) -c $< -o $@

clean:
	rm -f $(TARGET) $(OBJECTS)

install: $(TARGET)
	install -d /usr/local/lib/
	install -m 644 $(TARGET) /usr/local/lib/
	install -d /usr/local/include/
# 	install -m 644 StorageManager.hpp /usr/local/include/
# 	install -m 644 ./Structures/StorageTypes.hpp /usr/local/include/
	ldconfig

.PHONY: all clean install
